import { GET_TOKEN, SET_USER, GET_USER, SET_USERID } from './../constants/user';
import jwt_decode from 'jwt-decode'

const INITIAL_STATE = {
  user: {
    encryptedData: '',
    errMsg: '',
    iv: '',
    rawData: '',
    signature: '',
    userInfo: {
      avatarUrl: '',
      city: '',
      country: '',
      gender: 0, // 0 女， 1 男
      language: '',
      nickName: '',
      province: ''
    },
    userInfoServer: {
      id: -1, 
      username: '', // string: 用户名
      phoneNumber: null, // string|null: 手机号码
      nickName: null, // string|null: 昵称
      gender: 0,// 0|1|null: 女|男|未知
      state: 0,// 0|1: 用户状态,正常|封禁
      picture: '' // string(url)|null: 头像链接
    }
  },
  userId: -1,
}

export default function user (state = INITIAL_STATE, action) {
  switch (action.type) {
    // case GET_TOKEN:
    //   return {
    //     ...state,
    //     token: state.token
    //   }
    case GET_USER:
      return{
        ...state,
        user: state.user
      }
     case SET_USER:
       return {
         ...state,
         user: action.user
       }
    case SET_USERID:
      return {
        ...state,
        userId: action.userId
      }
     default:
       return state
  }
}
